<!DOCTYPE html>
<meta charset="utf-8" />

<link rel="stylesheet" href="ace_v1.3/assets/css/ui.jqgrid.css" />

<div class="search_panel">
<form action="mpbase/queryUnionfitList.do" method="post" onsubmit="return pageSearch(this);">
	<div style="display: block;" class="widget-body ">
		<div class="widget-main">
			<div class="rowt">
				<div class="col-sm-12">
					<div>
						<div class="search_elm" style="margin-left: 0px">
						<label class="label_search">发卡行名称:</label>
							<div class="search_input">
							<input id="search_issnam" type="text" name="issnam" placeholder="请输入发卡行名称">
							</div>
						</div>
						<div class="search_elm" style="margin-left: 0px">
						<label class="label_search">银行编码:</label>
							<div class="search_input">
							<input id="search_issnam" type="text" name="bankCode" placeholder="请输入银行编码">
							</div>
						</div>
						<div class="search_elm" style="margin-left: 0px">
						<label class="label_search">卡名称:</label>
							<div class="search_input">
							<input id="search_crdnam" type="text" name="crdnam" placeholder="请输入卡名称">
							</div>
						</div>
						<div class="search_elm" style="margin-left: 0px">
						<label class="label_search">标识取值:</label>
							<div class="search_input">
							<input id="search_binctt" type="text" name="binctt" placeholder="请输入发卡行标识取值">
							</div>
						</div>
						
						<div class="search_elm">
						<label class="label_search" >卡种:</label>
							<div class="search_input">
						    <select 
								 rel="obj.UNIONFIT_DCFLAG"
					 			 location="local" 
								 name="dcflag" 
					 			 id="search_dcflag" 
					 			 data-placeholder="请选择状态" style="width: 130px;vertical-align:middle;">
								<option value='' >----请选择----</option>
								</select>
							</div>
						</div>
						
						<div class="search_elm">
							<button class="btn btn-small btn_search" type="submit" title="搜索" > 搜索 </button>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	</form>
</div>
	<div class="rowt">
		<div class="col-xs-12">
			<table id="grid-table"></table>
			<div id="grid-pager"></div>
			<div style="margin-top: 10px">
				<span id="auth_btn">
					<a class="btn btn-small btn-add" onclick="addUnionfitView();">新增</a> 
					<a class="btn btn-small btn-update" onclick="eidtUnionfitView();"> 修改 </a> 
					<a class="btn btn-small btn-delete" onclick="removeUnionfit();">  删除 </a>
				</span>
				<span id="paging_bar" style="float: right"> </span>
			</div>
		</div>
	</div>


	<script type="text/javascript">
		var jqGrid;
		jQuery(function($) {
			var grid_selector = "#grid-table";
			var pager_selector = "#grid-pager";

			$(window).on(
					'resize.jqGrid',
					function() {
						$(grid_selector).jqGrid('setGridWidth',
								$(".page-content").width());
					})
			var parent_column = $(grid_selector).closest('[class*="col-"]');
			$(document).on(
					'settings.ace.jqGrid',
					function(ev, event_name, collapsed) {
						if (event_name === 'sidebar_collapsed'
								|| event_name === 'main_container_fixed') {
							setTimeout(function() {
								$(grid_selector).jqGrid('setGridWidth',
										parent_column.width());
							}, 0);
						}
					})
			jQuery(grid_selector).jqGrid({
				url : "mpbase/queryUnionfitList.do",
				datatype : "json",
				height : '100%',
				width : '100%',
				colNames : [ '银行编号','发卡行名称','银行编码','卡名称','Fit所在磁道','主账号','主账号所在磁道','发卡行标识起始字节','发卡行标识长度','发卡行标识取值','发卡行标识读取磁道','卡种'],
				colModel : [ {name : 'issno',      index : 'issno',      width : '100px' },
				             {name : 'issnam',      index : 'issnam',      width : '200px' }, 
				             {name : 'bankCode',    index : 'bankCode',    width : '80px' }, 
				             {name : 'crdnam',    index : 'crdnam',    width : '150px' }, 
				             {name : 'fitcrk',      index : 'fitcrk',    width : '100px' }, 
				             {name : 'crdctt',    index : 'crdctt',    width : '100px' }, 
				             {name : 'crdcrk',    index : 'crdcrk',    width : '120px' },
				             {name : 'binoff',    index : 'binoff',    width : '150px' }, 
				             {name : 'binlen',    index : 'binlen',    width : '120px' },
				             {name : 'binctt',    index : 'binctt',    width : '120px' }, 
				             {name : 'bincrk',    index : 'bincrk',    width : '150px' },
				             {name : 'dcflag',    index : 'dcflag',    width : '100px',ditcKey:'UNIONFIT_DCFLAG', formatter : gridFormatByDict }
				             ],
				viewrecords : true,
				rowNum : 10,
				rowList : [ 10, 20, 30 ],
				altRows : true,

				shrinkToFit : false,
				multiselect : true,//设置行可多选的 
				multiboxonly : true,//

				loadComplete : function() {
					var table = this;
					setTimeout(function() {
						//加载分页
						initPagingBar(grid_selector);
					}, 0);
				},
				beforeRequest : function() {//请求之前执行
					jqGrid = this;
				},
			});
			$(window).triggerHandler('resize.jqGrid');

			$(document).one('ajaxloadstart.page', function(e) {
				$(grid_selector).jqGrid('GridUnload');
				$('.ui-jqdialog').remove();
			});
			/* function unionfitDcflagFormat(cellvalue, options, rowObject){
				return DICT.get("UNIONFIT_DCFLAG")[cellvalue];
			} */
			
		});

		function addUnionfitView() {
			openDialog({
				dialogId : 'dlg-addUnionfitView',
				title : '新增卡BIN',
				pageUrl : 'mpbase/addUnionfitView.do',
				width : '75%',
			    height : '90%'
			});
		}
		function eidtUnionfitView() {
			var rows = $('#grid-table').jqGrid("getGridParam", "selarrrow");
			if (rows.length == 0) {
				msg.alert("警告", "当前没有选择数据项！", "error");
				return;
			}
			if (rows.length > 1) {
				msg.alert("警告", "不能同时选择多项数据！", "warn");
				return;
			}
			
			var binoff= $('#grid-table').jqGrid('getRowData',rows[0]).binoff;
			var binlen= $('#grid-table').jqGrid('getRowData',rows[0]).binlen;
			var binctt= $('#grid-table').jqGrid('getRowData',rows[0]).binctt;
			var bincrk= $('#grid-table').jqGrid('getRowData',rows[0]).bincrk;
			
			openDialog({
				dialogId : 'dlg-eidtUnionfitView',
				title : '编辑卡BIN',
				pageUrl : 'mpbase/eidtUnionfitView.do',
				dataUrl : "mpbase/queryUnionfitById.do?binoff=" + binoff+"&binlen="+binlen+"&binctt="+binctt+"&bincrk="+bincrk,
				width : '75%',
			    height : '90%',
				dataName : 'obj' 
			});
		}
		function removeUnionfit() {
			var rows = $('#grid-table').jqGrid("getGridParam", "selarrrow");
			if (rows.length == 0) {
				msg.alert("警告", "当前没有选择数据项！", "warn");
				return;
			}
			
			for (var i = 0; i < rows.length; i++) {
				var binoff= $('#grid-table').jqGrid('getRowData',rows[i]).binoff;
				var binlen= $('#grid-table').jqGrid('getRowData',rows[i]).binlen;
				var binctt= $('#grid-table').jqGrid('getRowData',rows[i]).binctt;
				var bincrk= $('#grid-table').jqGrid('getRowData',rows[i]).bincrk;
			}
			
			ids = ids.substring(0, ids.lastIndexOf(","));
			msg.confirm({title:'确认',position:'center',msg:'您确定要删除选中的数据吗？',call:function(ok){
				if(ok){
					$.ajax({
						type : "post",
						url : "mpbase/removeUnionfit.do?binoff=" + binoff+"&binlen="+binlen+"&binctt="+binctt+"&bincrk="+bincrk,
						dataType : 'json',
						success : function(result) {
							if (result.rspcod != 200) {
								msg.alert("错误", result.rspmsg + " 错误代码："
										+ result.rspcod, 'error');
							} else {
								msg.alert("提示", result.rspmsg, 'correct');
								$("#grid-table").trigger("reloadGrid");
							}
						},
						error : function(XMLHttpRequest, textStatus) {
							msg.alert("错误", "错误代码：" + XMLHttpRequest.status + ",错误描述："
									+ textStatus, 'error');
						}
					});

				}
			}});
			
		}
		
	</script>